package com.buba.livenuniappservernew.api.coachmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.livenuniappservernew.api.ImageFile.entity.ImageFile;
import com.buba.livenuniappservernew.api.ImageFile.mapper.ImageFileMapper;
import com.buba.livenuniappservernew.api.coachmanagement.pojo.CoachManagement;
import com.buba.livenuniappservernew.api.coachmanagement.mapper.CoachManagementMapper;
import com.buba.livenuniappservernew.api.coachmanagement.service.ICoachManagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.buba.livenuniappservernew.common.CommonResult;
import com.buba.livenuniappservernew.utils.RedisUtil;
import com.github.yulichang.query.MPJQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * <p>
 * 教练管理表
 服务实现类
 * </p>
 *
 * @author mading
 * @since 2024-09-04
 */
@Service
public class CoachManagementServiceImpl extends ServiceImpl<CoachManagementMapper, CoachManagement> implements ICoachManagementService {
    @Autowired
    private CoachManagementMapper coachManagementMapper;
    @Autowired
    private ImageFileMapper imageFileMapper;
    @Autowired
    private RedisUtil redisUtil;
    /**
     * 查询所有教练信息以及根据id单查教练信息
     * @param
     * @return
     */
    @Override
    public CommonResult listCoachManagement() {
        MPJQueryWrapper<CoachManagement> wrapper = new MPJQueryWrapper<>();
        wrapper.select("t.id,t.coach_name,t.coach_sex,t.coach_phone,t.coach_teaching_times," +
                "t.coach_information,t.coach_specialty,t.coach_experience,b.file_uuid_name")
                .join("JOIN",true,"image_file b on  t.coach_img = b.image_name");
        List<CoachManagement> list = coachManagementMapper.selectJoinList(CoachManagement.class, wrapper);
        redisUtil.lSet("listCoachManagement1",list,5000000);
        redisUtil.lSet("listCoachManagement2",list,6000000);
        return CommonResult.success(list);
    }
}
